package office.service.hr.impl;

import java.util.List;

import office.bo.hr.impl.Broadcast;
import office.domainset.BizDomainProviderSetImpl;
import office.service.hr.IBroadcastService;
import platform.common.dao.IDomainProvider;
import platform.common.dao.impl.DaoConfigException;
import platform.common.dao.impl.DaoException;
import platform.common.service.impl.BaseBizServiceImpl;

public class BroadcastService extends BaseBizServiceImpl implements IBroadcastService {

	@SuppressWarnings("unchecked")
	@Override
	public List<Broadcast> getAllBroadcast() {
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			IDomainProvider broadcastDP = domainProviderSetImpl.getBroadcastDP();
			List<Broadcast> list = (List<Broadcast>)domainProviderSetImpl.getDao().findAllByDomian(broadcastDP);
			return list;
		} catch (DaoException e) {
			log.error("", e);
			return null;
		} catch (DaoConfigException e) {
			log.error("", e);
			return null;
		}
	}

	@Override
	public void saveBroadcast(Broadcast broadcast) {
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			domainProviderSetImpl.getDao().saveOrUpdate(broadcast);
		} catch (DaoException e) {
			log.error("", e);
		}
	}

	@Override
	public Broadcast getBroadcastById(String id) {
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			IDomainProvider broadcastDP = domainProviderSetImpl.getBroadcastDP();
			Broadcast broadcast = (Broadcast)domainProviderSetImpl.getDao().findByIdAndDomain(broadcastDP, id);
			return broadcast;
		} catch (DaoException e) {
			log.error("", e);
			return null;
		} catch (DaoConfigException e) {
			log.error("", e);
			return null;
		}
	}

	@Override
	public void deleteBroadcastById(String id) {
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			IDomainProvider broadcastDP = domainProviderSetImpl.getBroadcastDP();
			domainProviderSetImpl.getDao().deleteById(broadcastDP, id);
		} catch (DaoException e) {
			log.error("", e);
		} catch (DaoConfigException e) {
			log.error("", e);
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Broadcast> getShowIndexBroadcast(String status) {
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			IDomainProvider broadcastDP = domainProviderSetImpl.getBroadcastDP();
			String params[] = {status};
			List<Broadcast> list = (List<Broadcast>)domainProviderSetImpl.getDao().findByHqlNameAndDomian(broadcastDP, "showIndexBroadcast", params);
			return list;
		} catch (DaoException e) {
			log.error("", e);
		} catch (DaoConfigException e) {
			log.error("", e);
		}
		return null;
	}

}
